﻿<%@ page pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/jsp/base/taglibs.jsp"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<link href="${ctx}/css/main.css" rel="stylesheet" type="text/css" />
	</head>
	<script language="javascript">
		var message = '${message}';
		if(message != ''){
			alert(message);
		}
		
		function submitAction(actionName){
			document.userForm.action = actionName ;
			document.userForm.submit();
		}
		
		function doDelete(action,id){
			if(confirm('是否确认删除？')){
				location.href = "${ctx}/" + action + "?id=" + id ;
			}
		}
		
		function saveAction(action) {
			userName = document.getElementById("userName").value;
			password = document.getElementById("password").value;
			id = document.getElementById("id").value;
			mobileNo = document.getElementById("mobileNo").value;
			telNo = document.getElementById("telNo").value;
			email = document.getElementById("email").value;
			realName = document.getElementById("realName").value;
			userCategory = document.getElementById("userCategory").value;
			if(userName == '') {
				alert('请输入用户名');
				return false;
			}
			if(!validateUsername()) return false;
			if(id == '' && password == ''){
				alert('请输入密码');
				return false;
			}
			if(mobileNo == '' && telNo == ''){
				alert('手机号码和固定电话至少输入一个');
				return false;
			}
			if(email == ''){
				alert('请输入电子邮箱地址');
				return false;
			}
			if(realName == ''){
				alert('请输入真实姓名');
				return false;
			}
			if(userCategory == ''){
				alert('请选择用户类别');
				return false;
			}
			if(!validateEmail()) return false;
			submitAction(action);
		}
		
		function validateUsername() {
			var pattern = /^[a-zA-Z]{1}[0-9a-zA-Z_]{1,}$/;
			userName = document.getElementById("userName").value; 
			if(userName.length < 4) {
				alert('用户名不能少于4个字符')
				return false;
			}
			if(pattern.test(userName) == false) {
				alert('用户名只能以字母开头，且必须由字母、数字或下划线组成');
				return false;
			}
			return true;
		}
		
		function validateEmail() {
			var emailpattern = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/; 
		   	email = document.getElementById("email").value; 
			if(emailpattern.test(email) == false) {
				alert('电子邮箱栏位不是有效的电子邮箱地址格式，请重新输入');
				return false;
			}
			return true;
		}
		
		var detail;
		function searchUserCompany() {
			userCategory = document.getElementById("userCategory").value;
			if(userCategory == ''){
				alert('请先选择用户类别');
				return false;
			}
			if(!detail || detail.closed) {
				detail = window.open("about:blank", "user_company_choose", "status,scrollbars,resizable=no,left=190,top=150,width=480,height=380");
			}
			userCompanyForm.type.value = userCategory;
			userCompanyForm.target = "user_company_choose";
			userCompanyForm.submit();
			detail.focus();
		}
		
		function clearCompanyInfo() {
			document.getElementById('companyId').value = '';
			document.getElementById('companyName').value = '';
		}
	</script>
	
	<body>
		<form name="userCompanyForm" id="userCompanyForm" method="post" action="searchUserCompany.ac">
			<input type="hidden" name="type" id="type" value="">
		</form>
		<form method="post" action="" name="userForm">
			<table border="0" cellspacing="1" cellpadding="3" align="center" width="100%">
				<tr>
					<td class="td11" align="left" colspan="4">
						<input type="button" name="save" value="保存" onClick="saveAction('saveUser.ac');">
						<c:if test="${!empty userInfo.id}">&nbsp;&nbsp;<input type="button" name="delete" value="删除" onClick="doDelete('deleteUser.ac','${userInfo.id}');"></c:if>
						&nbsp;&nbsp;<input type="button" name="back" value="返回" onClick="submitAction('userInfoManage.ac');">
					</td>
				</tr>
				<c:if test="${!empty userInfo.id}">
					<tr>
						<td colspan="4"><span style="color:red">提示：如不需要更改密码，则密码栏位不用输入</span></td>
					</tr>
				</c:if>
				<tr>
					<td width="20%" class="td2"> 
						用户名 <span style="color:red;vertical-align:middle;">*</span>
					</td>
					<td width="30%" class="td2">
						<input type="hidden" name="id" size="32" value="${userInfo.id}">
						<c:if test="${empty userInfo.id}">
							<input type="text" name="userName" size="32" value="${userInfo.userName}" onblur="validateUsername();">
						</c:if>
						<c:if test="${!empty userInfo.id}">
							<input type="text" readonly="readonly" style="color:grey" name="userName" size="32" value="${userInfo.userName}">
						</c:if>
					</td>
					<td width="20%" class="td2">
						密码 <span style="color:red;vertical-align:middle;">*</span>
					</td>
					<td width="30%" class="td2">
						<input type="password" name="password" size="32" value="">
					</td>
				</tr>
				<tr>
					<td width="20%" class="td2">
						手机号码 <span style="color:red;vertical-align:middle;">*</span>
					</td>
					<td width="30%" class="td2">
						<input type="text" name="mobileNo" size="32" value="${userInfo.mobileNo}">
					</td>
					<td width="20%" class="td2"> 
						固定电话 <span style="color:red;vertical-align:middle;">*</span>
					</td>
					<td width="30%" class="td2">
						<input type="text" name="telNo" size="32" value="${userInfo.telNo}">
					</td>
				</tr>
				<tr>
					<td width="20%" class="td2">
						电子邮箱 <span style="color:red;vertical-align:middle;">*</span>
					</td>
					<td width="30%" class="td2">
						<input type="text" name="email" size="32" value="${userInfo.email}" onblur="validateEmail();">
					</td>
					<td width="20%" class="td2"> 
						性别 <span style="color:red;vertical-align:middle;">*</span> 
					</td>
					<td width="30%" class="td2">
						<c:if test="${userInfo.sex != 0}">
							<input type="radio" name="sex" size="15" value="1" checked="true">男
							&nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="sex" size="15" value="0">女
						</c:if>
						<c:if test="${userInfo.sex == 0}">
							<input type="radio" name="sex" size="15" value="1">男
							&nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="sex" size="15" value="0" checked="true">女
						</c:if>
					</td>
				</tr>
				<tr>
					<td width="20%" class="td2">
						真实姓名 <span style="color:red;vertical-align:middle;">*</span>
					</td>
					<td width="30%" class="td2">
						<input type="text" name="realName" size="32" value="${userInfo.realName}">
					</td>
					<td width="20%" class="td2"> 
						用户类别 <span style="color:red;vertical-align:middle;">*</span> 
					</td>
					<td width="30%" class="td2">
						<select name="userCategory" style="width:200px" onchange="clearCompanyInfo();">
							<c:if test="${userInfo.userCategory != 1}">
								<option value="0" selected="selected">企业用户</option>
								<option value="1">校园用户</option>
							</c:if>
							<c:if test="${userInfo.userCategory == 1}">
								<option value="0">企业用户</option>
								<option value="1" selected="selected">校园用户</option>
							</c:if>
						</select>
					</td>
				</tr>
				<tr>
					<td width="20%" class="td2">
						所属公司（院校） 
					</td>
					<td width="30%" class="td2">
						<input type="hidden" name="companyId" size="32" value="${userInfo.companyId}">
						<input type="text" readonly="readonly" name="companyName" size="28" value="${userInfo.companyName}">
						<img onclick="searchUserCompany()" src="${ctx}/images/index/search.gif" width="16" height="16" align="absmiddle">
					</td>
					<td width="20%" class="td2"> 
						是否公司（院校）管理员 
					</td>
					<td width="30%" class="td2">
						<select name="adminFlag" style="width:200px">
							<c:if test="${userInfo.adminFlag != 1}">
								<option value="0" selected="selected">否</option>
								<option value="1">是</option>
							</c:if>
							<c:if test="${userInfo.adminFlag == 1}">
								<option value="0">否</option>
								<option value="1" selected="selected">是</option>
							</c:if>
						</select>
					</td>
				</tr>
			</table>
		</form>
	</body>
</html>